package com.example.goods.controller;

import com.alibaba.fastjson.JSONObject;
import com.example.commons.filter.RequestFilter;
import com.example.commons.response.ResponseResult;
import com.example.commons.response.ResultCode;
import com.example.goods.service.OrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/order")
public class OrdersController {
    @Autowired
    OrdersService ordersService;

    @PostMapping("/place")
    public ResponseResult place(RequestFilter requestFilter) {
        JSONObject bodyJson = requestFilter.getRequestBodyJson();
        String artId = bodyJson.getString("artId");
        int number = bodyJson.getIntValue("number");
        String id = requestFilter.getLoginData().getId();
        ordersService.orderRedisson(id, artId, number);
        return new ResponseResult(ResultCode.SUCCESS, null, null);
    }
}
